doctype html
html.no-focus lang="en"
  head
    title = @html_title || '登录CRM系统'
    meta charset='utf-8'
    meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
    meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"
    meta name="renderer" content="webkit"
    meta http-equiv="cleartype" content="on"
    meta name="HandheldFriendly" content="True"
    meta name="MobileOptimized" content="320"
    - if content_for?(:title)
      = yield(:title)
    - else
      title CRM-System
    = csrf_meta_tags
    = action_cable_meta_tag
    = content_for?(:head) ? yield(:head) : ''
    = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
    = javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
    = favicon_link_tag "favicon.ico"


  body
    .content.overflow-hidden
      .row
        .col-sm-8.col-sm-offset-2.col-md-6.col-md-offset-3.col-lg-4.col-lg-offset-4
          = yield
  #page-loader
javascript:
  show_notice("#{flash[:notice]}")
  error_notice("#{flash[:error]}")

  // 获取验证码操作
  $('.get_code').on('click', function () {
    var m = $('.code-mobile').val(),
        type = $(this).data('codeType'),
        $this = $(this),
        timer = null,
        retry_sec = 120

    if (/^1[34578]\d{9}$/.test(m)) {
      $.ajax({
        url: "/send_validate_code",
        type: 'put',
        data: {mobile: m, type: type},
        dataType: 'json',
        success: function (res) {
          if(res.result){
            show_notice('验证码已发送！')
            if(res.msg!=''){
              sweetAlert('验证码：'+res.msg)
            }
            $this.attr('disabled', true)
            var sec = retry_sec;
            timer = setInterval(function(){
              sec -= 1;
              if (sec > 0) {
                $this.html(sec+'s后重新获取');
              } else {
                clearInterval(timer);
                $this.attr('disabled', false)
                $this.html('获取验证码')
              }
            },1000)
          }else{
            alert('发送失败！'+res.msg)
          }
        },
        error: function (res) {
          error_notice('操作失败！' + res.msg)
        }
      })
    } else {
      error_notice('请输入正确的手机号')
    }
    return false
  });